package com.sj.controller;

import com.sj.common.lang.ApiResult;
import com.sj.entity.Dict;
import com.sj.entity.DictDetail;
import com.sj.service.DictDetailService;
import com.sj.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 字典详情表 前端控制器
 * </p>
 *
 * @author 孙峻
 * @since 2022-03-09
 */
@RestController
@RequestMapping("/dictDetail")
@Api(tags = "字典模块")
public class DictDetailController {

    @Autowired
    private DictDetailService dictDetailService;

    @Autowired
    private DictService dictService;

    @ApiOperation("获取字典列表")
    @GetMapping("/list/{name}")
    public ApiResult getDictDetailList(@PathVariable String name) {
        Dict dict = dictService.lambdaQuery().eq(Dict::getName, name).one();
        List<DictDetail> list = dictDetailService.lambdaQuery().eq(DictDetail::getDictId, dict.getId()).list();
        return ApiResult.success(list);
    }

}
